package com.hudongwx.godoffood.activity.home_activity;

import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.MediaController;
import android.widget.TextView;
import android.widget.VideoView;

import com.hudongwx.godoffood.R;

import org.xutils.view.annotation.ContentView;
import org.xutils.view.annotation.Event;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

@ContentView(R.layout.activity_video)
public class VideoActivity extends AppCompatActivity {
    private String TAG = "VideoActivity";
    @ViewInject(R.id.video)
    VideoView videoView;
    @ViewInject(R.id.video_title)
    TextView textView;

    @ViewInject(R.id.video_ll)
    LinearLayout ll;
    boolean flag;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        x.view().inject(this);
        flag=false;
        String url = getIntent().getStringExtra("url");
        String title = getIntent().getStringExtra("title");
        //设置视频标题
        textView.setText(title);
        Log.i(TAG, "onCreate: "+url);
        videoView.setMediaController(new MediaController(this));
        Uri uri = Uri.parse(url);
        videoView.setVideoURI(uri);
        //让程序运行时屏幕是水平显示的
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

        videoView.start();
        videoView.requestFocus();
    }


    @Event(R.id.video_back)
    private void back(View view){
        super.onBackPressed();
    }

    @Event(R.id.video_fl)
    private void click(View view){
        if (!flag){
            ll.setVisibility(View.INVISIBLE);
            flag=true;
        }else {
            ll.setVisibility(View.VISIBLE);
            flag=false;
        }
    }
}
